#ifndef VEHICLESTATEMANAGER_H_INCLUDED
#define VEHICLESTATEMANAGER_H_INCLUDED

#include <iostream>
#include <list>
#include "RouteTypes.h"
#include "SqLiteDbWrapper.h"
#include "GpsWrapper.h"
#include <boost/thread.hpp>


using namespace std;

//VehicleStateManager.h - The handler for managing the progression of a vehicle
//through a route. Also acts as a storage class for the route's entities.
//This may need optimising if routes get particularly large.



class VehicleStateManager{

    private:
        //IO
        SqLiteDbWrapper* db;
        GpsWrapper gps;
        float gpsBuffer[2];
        //Handle to thread used to ensure ESM thread terminates if VSM halts
        boost::thread esmThread;


        //Architectural
        bool routeIsCircular;
        Node currentNode;
        list<Path> pathList;
        list<Path>::iterator listIterator;

        //State Machine Methods
        bool setNode();
        bool atNextNode();
        void nodeListenLoop();
        void lastNodeLoop();
        void changeState(VehicleStates newState);

    public:
        VehicleStateManager(SqLiteDbWrapper* connection, int RouteID);
        ~VehicleStateManager();

        //TODO: find a better encapsulated way for changing VehicleState
        VehicleStates State;

};

#endif
